<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>python之Django搭建web(1) | 静待花开</title><meta name="author" content="brad 随风起舞"><meta name="copyright" content="brad 随风起舞"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="这里我直接进入主题，前提是已经安装了python 安装Virtualenv命令安装：pip install virtualenv重点强调一下安装这个虚拟环境不是必须的。但是有他的好处，如下所示：  我们安装的任何东西包括django在内，都会被安装在虚拟环境中 每个项目都会在一个虚拟环境中，这就像是每个django项目都有一个沙盒。你想怎么玩就怎么玩，不会破坏虚拟环境之外的东西。   接下来创建一">
<meta property="og:type" content="article">
<meta property="og:title" content="python之Django搭建web(1)">
<meta property="og:url" content="https://zhangbo4881820.gitee.io/myblog/posts/56046/index.html">
<meta property="og:site_name" content="静待花开">
<meta property="og:description" content="这里我直接进入主题，前提是已经安装了python 安装Virtualenv命令安装：pip install virtualenv重点强调一下安装这个虚拟环境不是必须的。但是有他的好处，如下所示：  我们安装的任何东西包括django在内，都会被安装在虚拟环境中 每个项目都会在一个虚拟环境中，这就像是每个django项目都有一个沙盒。你想怎么玩就怎么玩，不会破坏虚拟环境之外的东西。   接下来创建一">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2019-10-24T16:10:38.000Z">
<meta property="article:modified_time" content="2023-09-07T09:44:01.880Z">
<meta property="article:author" content="brad 随风起舞">
<meta property="article:tag" content="python">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/myblog/img/favicon.png"><link rel="canonical" href="https://zhangbo4881820.gitee.io/myblog/posts/56046/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/myblog/css/index.css"><link rel="stylesheet" href="/myblog/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="/myblog/css/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/myblog/',
  algolia: undefined,
  localSearch: {"path":"/myblog/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'python之Django搭建web(1)',
  isPost: true,
  isHome: false,
  isHighlightShrink: true,
  isToc: true,
  postUpdate: '2023-09-07 17:44:01'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 7.0.0-rc2"><link rel="alternate" href="/myblog/atom.xml" title="静待花开" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分享</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/myblog/" title="静待花开"><span class="site-name">静待花开</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分享</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">python之Django搭建web(1)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-10-24T16:10:38.000Z" title="发表于 2019-10-25 00:10:38">2019-10-25</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-09-07T09:44:01.880Z" title="更新于 2023-09-07 17:44:01">2023-09-07</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myblog/categories/pythonWeb/">pythonWeb</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="python之Django搭建web(1)"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><p><strong>这里我直接进入主题，前提是已经安装了python</strong></p>
<h2 id="安装Virtualenv"><a href="#安装Virtualenv" class="headerlink" title="安装Virtualenv"></a>安装Virtualenv</h2><p>命令安装：<br><code>pip install virtualenv</code><br><img src="/myblog/../../../image/pip-virtualenv.png"><br><code>重点强调一下安装这个虚拟环境不是必须的。但是有他的好处，如下所示：</code></p>
<ol>
<li>我们安装的任何东西包括django在内，都会被安装在虚拟环境中</li>
<li>每个项目都会在一个虚拟环境中，这就像是每个django项目都有一个沙盒。你想怎么玩就怎么玩，不会破坏虚拟环境之外的东西。</li>
</ol>
<ul>
<li>接下来创建一个指定文件夹<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">mkdir myproject</span><br><span class="line">cd myproject</span><br></pre></td></tr></table></figure>
<img src="/myblog/../../../image/myproject.png"></li>
<li>然后使用命令在这个文件夹创建虚拟环境<br>  <code>virtualenv venv</code><br>  <img src="/myblog/../../../image/venv.png"><br>  我们的虚拟环境就被创建了，要使用它，还需激活一下。使用命令<br>  <code>venv\Scripts\activate</code><br>  你就可以看到（venv）在命令行前，就像下图<br>  <img src="/myblog/../../../image/activate.png"><br>  顺便提下，关闭虚拟环境的命令是<br>  <code>venv\Scripts\deactivate.bat</code></li>
</ul>
<h2 id="安装Django"><a href="#安装Django" class="headerlink" title="安装Django"></a>安装Django</h2><p><strong>特别提下因为我们是中国，天然下载国外的东西慢，至于原因不需要解释，下面是解决方法</strong></p>
<h3 id="提升pip-安装速度"><a href="#提升pip-安装速度" class="headerlink" title="提升pip 安装速度"></a>提升pip 安装速度</h3><ul>
<li>换个数据源，比如用豆瓣的(临时使用)：<br>  pip install -i <a href="http://pypi.douban.com/simple">http://pypi.douban.com/simple</a> –trusted-host pypi.douban.com django&#x3D;&#x3D;1.11.4</li>
<li>长期使用<ol>
<li>创建一个隐藏目录名字是  .pip <code>mkdir ~/.pip</code></li>
<li>进入 .pip 的目录创建一个 pip.conf 的文件</li>
<li>编辑 pip.conf 文件 <figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">[global]</span><br><span class="line">index-url = http://pypi.douban.com/simple</span><br><span class="line">[install]</span><br><span class="line">trusted-host = pypi.douban.com</span><br></pre></td></tr></table></figure></li>
</ol>
</li>
</ul>
<p>直接安装使用命令：<br><code>pip install django</code></p>
<h2 id="启动一个新项目"><a href="#启动一个新项目" class="headerlink" title="启动一个新项目"></a>启动一个新项目</h2><p>直接命令 <code>django-admin startproject myproject</code><br>命令行工具<strong>django-admin</strong>是安装django后自动安装的<br>执行上面的启动项目命令后会生成一个django项目的基本文件结构，就像下面这样：</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">myproject/                  &lt;-- higher level folder</span><br><span class="line"> |-- myproject/             &lt;-- django project folder</span><br><span class="line"> |    |-- myproject/</span><br><span class="line"> |    |    |-- __init__.py</span><br><span class="line"> |    |    |-- settings.py</span><br><span class="line"> |    |    |-- urls.py</span><br><span class="line"> |    |    |-- wsgi.py</span><br><span class="line"> |    +-- manage.py</span><br><span class="line"> +-- venv/                  &lt;-- virtual environment folder</span><br></pre></td></tr></table></figure>
<p>我们的初始化项目是由5个文件组成的：</p>
<ul>
<li><strong>manage.py:</strong> 这是快捷使用<strong>django-admin</strong>命令行工具的。经常被用作我们项目的管理命令。比如启动服务，启动测试等。</li>
<li><strong><strong>init</strong>.py:</strong> 这个空文件夹用来告诉python,这个文件夹是一个Python 包。</li>
<li><strong>settings.py:</strong> 这个文件包含所有项目的配置。我们讲总会提到这个文件。</li>
<li><strong>urls.py:</strong> 这个文件是负责在项目中的路由和路径的映射的。</li>
<li><strong>wsgi.py:</strong> 这个文件是一个简单的接口的入口<br>不需要多余操作，直接命令启动项目。<br>首先进入manage.py这一层目录然后执行命令：<code>python manage.py runserver</code><br>然后在网页输入<code> http://127.0.0.1:8000</code>就能看到效果。</li>
</ul>
<h2 id="Django-Apps"><a href="#Django-Apps" class="headerlink" title="Django Apps"></a>Django Apps</h2><p>在Django知识体系中，我们应该知道两个重要的概念：</p>
<ul>
<li>**app:**是一个网站应用。一个app是由一系列的模块组合成的。（数据库表），view,templates,tests.</li>
<li>**project:**是配置和应用的集合。一个项目可以由多个app或者单个app组成</li>
</ul>
<p><strong>没有项目的情况下是不能运行app的。</strong><br>闲话少说，直接撸个app.创建一个简单的Board Web App，进入manage.py 文件目录下，执行一条命令如下：<br><code>django-admin startapp boards</code><br>使用完命令后，会生成如下目录结构</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">myproject/</span><br><span class="line"> |-- myproject/</span><br><span class="line"> |    |-- boards/                &lt;-- our new django app!</span><br><span class="line"> |    |    |-- migrations/</span><br><span class="line"> |    |    |    +-- __init__.py</span><br><span class="line"> |    |    |-- __init__.py</span><br><span class="line"> |    |    |-- admin.py</span><br><span class="line"> |    |    |-- apps.py</span><br><span class="line"> |    |    |-- models.py</span><br><span class="line"> |    |    |-- tests.py</span><br><span class="line"> |    |    +-- views.py</span><br><span class="line"> |    |-- myproject/</span><br><span class="line"> |    |    |-- __init__.py</span><br><span class="line"> |    |    |-- settings.py</span><br><span class="line"> |    |    |-- urls.py</span><br><span class="line"> |    |    |-- wsgi.py</span><br><span class="line"> |    +-- manage.py</span><br><span class="line"> +-- venv/</span><br></pre></td></tr></table></figure>
<p>接下来探索下每个文件的作用：</p>
<ul>
<li><strong>migrations&#x2F;:<strong>在这个文件中Django存储了一些保持追踪你在</strong>models.py</strong>中做出的改变的文件，以便保持数据和<strong>models.py</strong>的同步性</li>
<li>**admin.py:**这是为了建立Django App 调用 Django Admin 的配置文件</li>
<li>**apps.py:**这是App自身的配置文件</li>
<li>**models.py:**这里是用来定义我们web应用的实体。model会被Django自动映射进数据库表</li>
<li>**tests.py:**这个文件是用来写APP的测试单元的</li>
<li>**views.py:**视图层，用来处理循环处理我们web应用的request&#x2F;response</li>
</ul>
<p>现在我们已经创建第一个app,接下来进行配置我们的项目来使用这个app<br>这个时候，我们打开<strong>settings.py</strong>，找到<code>INSTALLED_APPS</code>这个变量：</p>
<p><strong>settings.py</strong></p>
<pre><code>INSTALLED_APPS = [
    &#39;django.contrib.admin&#39;,
    &#39;django.contrib.auth&#39;,
    &#39;django.contrib.contenttypes&#39;,
    &#39;django.contrib.sessions&#39;,
    &#39;django.contrib.messages&#39;,
    &#39;django.contrib.staticfiles&#39;,
]
</code></pre>
<p>通过以上我们可以看到，Django已经实例化了6个app.他们提供一些大多数web应用需要的通用的功能，像authentication（权限认证），sessions，staticfiles（静态文件管理：images, javascripts, css, etc）</p>
<p>然后把我们的app添加进<code>INSTALLED_APPS:</code></p>
<pre><code>INSTALLED_APPS = [
    &#39;django.contrib.admin&#39;,
    &#39;django.contrib.auth&#39;,
    &#39;django.contrib.contenttypes&#39;,
    &#39;django.contrib.sessions&#39;,
    &#39;django.contrib.messages&#39;,
    &#39;django.contrib.staticfiles&#39;,

    &#39;boards&#39;,
]
</code></pre>
<h2 id="HelloWorld"><a href="#HelloWorld" class="headerlink" title="HelloWorld"></a>HelloWorld</h2><p>万物之起始HelloWorld。<br>首先在<strong>boards</strong>app里面打开<strong>views.py</strong>文件，并且添加如下代码：<br><strong>views.py</strong></p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">from django.http import HttpResponse</span><br><span class="line"></span><br><span class="line">def home(request):</span><br><span class="line">    return HttpResponse(&#x27;Hello, World!&#x27;)</span><br></pre></td></tr></table></figure>
<p>Views 是Python函数，他接收一个<code>HttpRequest</code>对象返回一个<code>HttpResponse</code>对象</p>
<p>在上面的代码中，我们定义一个<strong>home</strong>的view,并且简单的返回“hello,World”的消息</p>
<p>接下来，我们要告诉Django去为这个view服务。这个操作在<strong>urls.py</strong>文件中完成：<br><strong>urls.py</strong><br>    from django.conf.urls import url<br>    from django.contrib import admin</p>
<pre><code>from boards import views

urlpatterns = [
    url(r&#39;^$&#39;, views.home, name=&#39;home&#39;),
    url(r&#39;^admin/&#39;, admin.site.urls),
]   
</code></pre>
<p>在这里我加入了 <code>url(r&#39;^$&#39;, views.home, name=&#39;home&#39;)</code> 还有从我们的<strong>boards</strong> app引用的<strong>views</strong>模块.<br>使用 <code>from boards import views</code><br>上面用的是正则表达式去匹配请求路径.对于我们 app 里的 <strong>home</strong> view,我使用<code>^$</code>,这个可以匹配一个空路径，例如（<strong><a href="http://127.0.0.1:8000/">http://127.0.0.1:8000</a></strong>）。<br>如果我想匹配**<a href="http://127.0.0.1:8000/homepage/**%E9%82%A3%E4%B9%88%E6%88%91%E7%9A%84URL%E8%AF%A5%E5%86%99%E6%88%90">http://127.0.0.1:8000/homepage/**那么我的URL该写成</a><br><code>url(r&#39;^homepage/$&#39;, views.home, name=&#39;home&#39;)</code></p>
<p>启动项目：<br>    python manage.py runserver</p>
<p>在网页输入<a href="http://127.0.0.1:8000/">http://127.0.0.1:8000</a><br><img src="/myblog/../../../image/hello-world.png"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://zhangbo4881820.gitee.io/myblog">brad 随风起舞</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://zhangbo4881820.gitee.io/myblog/posts/56046/">https://zhangbo4881820.gitee.io/myblog/posts/56046/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://zhangbo4881820.gitee.io/myblog" target="_blank">静待花开</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/myblog/tags/python/">python</a></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/myblog/posts/7504/" title="解决git有些文件不能上传"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">解决git有些文件不能上传</div></div></a></div><div class="next-post pull-right"><a href="/myblog/posts/64938/" title="git配置多平台SSH"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">git配置多平台SSH</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/myblog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">brad 随风起舞</div><div class="author-info__description">有些事情需要一辈子的沉淀</div></div><div class="card-info-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/xxxxx" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:xxxxxx@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85Virtualenv"><span class="toc-number">1.</span> <span class="toc-text">安装Virtualenv</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85Django"><span class="toc-number">2.</span> <span class="toc-text">安装Django</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%90%E5%8D%87pip-%E5%AE%89%E8%A3%85%E9%80%9F%E5%BA%A6"><span class="toc-number">2.1.</span> <span class="toc-text">提升pip 安装速度</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8%E4%B8%80%E4%B8%AA%E6%96%B0%E9%A1%B9%E7%9B%AE"><span class="toc-number">3.</span> <span class="toc-text">启动一个新项目</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Django-Apps"><span class="toc-number">4.</span> <span class="toc-text">Django Apps</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HelloWorld"><span class="toc-number">5.</span> <span class="toc-text">HelloWorld</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/15695/" title="jenkins（1）">jenkins（1）</a><time datetime="2023-09-14T02:17:44.000Z" title="发表于 2023-09-14 10:17:44">2023-09-14</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/22012/" title="wsl的Ubuntu子系统（1）">wsl的Ubuntu子系统（1）</a><time datetime="2023-09-13T08:42:19.000Z" title="发表于 2023-09-13 16:42:19">2023-09-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/30302/" title="effective-java-(接口优于抽象类)">effective-java-(接口优于抽象类)</a><time datetime="2023-09-12T08:12:48.000Z" title="发表于 2023-09-12 16:12:48">2023-09-12</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/9473/" title="effective-java(创建和销毁对象--组合的形式优于继承)">effective-java(创建和销毁对象--组合的形式优于继承)</a><time datetime="2023-09-11T08:23:19.000Z" title="发表于 2023-09-11 16:23:19">2023-09-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/16107/" title="Hello World">Hello World</a><time datetime="2023-09-07T09:44:01.910Z" title="发表于 2023-09-07 17:44:01">2023-09-07</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By brad 随风起舞</div><div class="framework-info"><span>框架 </span><a href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/myblog/js/utils.js"></script><script src="/myblog/js/main.js"></script><script src="/myblog/js/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/myblog/js/search/local-search.js"></script></div></div></body></html>